﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace WeatherServiceLibrary.Code
{
    [DataContract]
    public class StationObservation : BaseWeather
    {
        private string _stationName;

        [DataMember]
        public string StationName
        {
            get { return _stationName; }
            set { }
            //set { _stationId = value; }
        }
        private string _phenomenon;

        [DataMember]
        public string Phenomenon
        {
            get { return _phenomenon; }
            set { }
            //set { _phenomenon = value; }
        }
        private DateTime _timestamp;

        [DataMember]
        public DateTime Timestamp
        {
            get { return _timestamp; }
            set { }
            //set { _timestamp = value; }
        }
        private double? _visibility;

        [DataMember]
        public double? Visibility
        {
            get { return _visibility; }
            set { }
            //set { _visibility = value; }
        }
        private double? _precipitations;

        [DataMember]
        public double? Precipitations
        {
            get { return _precipitations; }
            set { }
            //set { _precipitations = value; }
        }
        private double? _airPressure;

        [DataMember]
        public double? AirPressure
        {
            get { return _airPressure; }
            set { }
            //set { _airPressure = value; }
        }
        private double? _relativeHumidity;

        [DataMember]
        public double? RelativeHumidity
        {
            get { return _relativeHumidity; }
            set { }
            //set { _relativeHumidity = value; }
        }
        private double? _airTemperature;

        [DataMember]
        public double? AirTemperature
        {
            get { return _airTemperature; }
            set { }
            //set { _airTemperature = value; }
        }
        private double? _windDirection;

        [DataMember]
        public double? WindDirection
        {
            get { return _windDirection; }
            set { }
            //set { _windDirection = value; }
        }
        private double? _windSpeed;

        [DataMember]
        public double? WindSpeed
        {
            get { return _windSpeed; }
            set { }
            //set { _windSpeed = value; }
        }
        private double? _windSpeedMax;

        [DataMember]
        public double? WindSpeedMax
        {
            get { return _windSpeedMax; }
            set { }
            //set { _windSpeedMax = value; }
        }

        [DataMember]
        public string All
        {
            get
            {
                StringBuilder str = new StringBuilder();
                str.AppendFormat("\r\n At {0} in {1}: ",
                                  Timestamp, StationName);
                if (AirTemperature != null) str.AppendFormat("\r\n Temperature: {0} °C", AirTemperature);
                if (Visibility != null) str.AppendFormat("\r\n Visibility: {0} km",Visibility);
                if (Precipitations != null) str.AppendFormat("\r\n Percipitations: {0} mm",Precipitations);
                if (Phenomenon != null) str.Append("\r\n Phenomenon: " + Phenomenon);
                if (AirPressure != null) str.AppendFormat("\r\n Air pressure: {0} hPa",AirPressure);
                if (RelativeHumidity != null) str.AppendFormat("\r\n Relative humidity: {0} %", RelativeHumidity);
                if (WindDirection != null) str.AppendFormat("\r\n Wind direction: {0} °", WindDirection);
                if (WindSpeed != null) str.AppendFormat(",\r\n speed: {0} m/s", WindSpeed);
                if (WindSpeedMax != null) str.AppendFormat(",\r\n maximum speed: {0} m/s", WindSpeedMax);

                return str.ToString();
            }
            set { }
        }

        public StationObservation(DBA.WeatherDB.StationObservation statObs)
        {
            this._stationName = statObs.Station.name;
            Id = statObs.StationObservationID;
            if (statObs.Phenomenon != null)
            {

                this._phenomenon = new Phenomenon(statObs.Phenomenon).Name;
            }
            else { this._phenomenon = null; }
            this._timestamp = (DateTime)statObs.Timestamp;
            this._visibility = statObs.Visibility;
            this._precipitations = statObs.Precipitations;
            this._airPressure = statObs.Airpressure;
            this._relativeHumidity = statObs.RelativeHumidity;
            this._airTemperature = statObs.AirTemperature;
            this._windDirection = statObs.WindDirection;
            this._windSpeed = statObs.WindSpeed;
            this._windSpeedMax = statObs.WindSpeedMax;

        }
    }
}
